function e(e, t, i) {
    return t in e ? Object.defineProperty(e, t, {
        value: i,
        enumerable: !0,
        configurable: !0,
        writable: !0
    }) : e[t] = i, e;
}

Object.defineProperty(exports, "__esModule", {
    value: !0
});

var t = function(e) {
    return e && e.__esModule ? e : {
        default: e
    };
}(require("../../../utils/util"));

exports.default = {
    $$formPreset: {},
    $$submitForm: function(e) {
        var i = this, a = e.currentTarget.dataset, r = a.form, n = a.fields, o = a.preset;
        this.$$formPreset = o;
        var s = this.$$verifyForm(n);
        if (s) t.default.qAlert(s); else {
            var u = n.map(function(e) {
                return {
                    fieldid: +e.fieldid,
                    value: e.value
                };
            }), d = getCurrentPages();
            setTimeout(function() {
                i.$emit("form:submit", {
                    formid: r.formid,
                    datas: u,
                    fields: n,
                    route: d[d.length - 1].route
                });
            }, 100);
        }
    },
    $$verifyForm: function(e) {
        for (var t = 0; t < e.length; t++) {
            var i = e[t];
            if (1 == +i.isrequire && !i.value) return i.construct.hint || i.title;
        }
        return "";
    },
    $$formHourPickerChange: function(t) {
        var i = t.currentTarget.dataset, a = i.preset, r = i.fieldindex, n = i.range, o = t.detail.value, s = n[0][o[0]] + " " + n[1][o[1]] + ":" + n[2][o[2]] + ":00";
        this.setData(e({}, a.position + "[" + a.index + "].data.fields[" + r + "].value", s));
    },
    $$formDatePickerChange: function(t) {
        var i = t.currentTarget.dataset, a = i.preset, r = i.fieldindex;
        this.setData(e({}, a.position + "[" + a.index + "].data.fields[" + r + "].value", t.detail.value));
    },
    $$setFormInputValue: function(t) {
        var i, a = t.currentTarget.dataset, r = a.preset, n = a.fieldindex;
        this.setData((i = {}, e(i, r.position + "[" + r.index + "].data.fields[" + n + "].value", t.detail.value), 
        e(i, r.position + "[" + r.index + "].data.fields[" + n + "].focusing", !1), i));
    },
    $$setFormTextareaFocus: function(t) {
        var i = t.currentTarget.dataset, a = i.preset, r = i.fieldindex;
        this.setData(e({}, a.position + "[" + a.index + "].data.fields[" + r + "].focusing", !0));
    },
    $$handleFormSingleChoice: function(t) {
        var i = t.currentTarget.dataset, a = i.preset, r = i.fieldindex;
        this.setData(e({}, a.position + "[" + a.index + "].data.fields[" + r + "].value", t.detail.value));
    },
    $$handleFormMultipleChoice: function(e) {
        this.$$handleFormChoice(e, "multiple");
    },
    $$handleFormChoice: function(t, i) {
        var a, r = t.currentTarget.dataset, n = r.preset, o = r.index, s = r.fieldindex, u = r.options, d = 1 == +u[o].isdefault ? 0 : 1, l = [];
        ("single" !== i || d) && ((u = u.map(function(e, t) {
            return t === o ? e.isdefault = d : "single" === i && (e.isdefault = 1 == +d ? 0 : 1), 
            e;
        })).forEach(function(e) {
            1 == +e.isdefault && l.push(e.value);
        }), this.setData((a = {}, e(a, n.position + "[" + n.index + "].data.fields[" + s + "].construct.option", u), 
        e(a, n.position + "[" + n.index + "].data.fields[" + s + "].value", l.join(",")), 
        a)));
    },
    $$clearForm: function(t) {
        var i = this.$$formPreset, a = t.map(function(e) {
            return e.value = "", 3 != +e.type && 4 != +e.type || (e.construct.option = e.construct.option.map(function(e) {
                return e.isdefault = 0, e;
            })), e;
        });
        this.setData(e({}, i.position + "[" + i.index + "].data.fields", a));
    }
};